package com.wugui.datatx.core.biz.client;

import com.wugui.datatx.core.biz.AdminBiz;
import com.wugui.datatx.core.biz.model.HandleCallbackParam;
import com.wugui.datatx.core.biz.model.HandleProcessCallbackParam;
import com.wugui.datatx.core.biz.model.RegistryParam;
import com.wugui.datatx.core.biz.model.ReturnT;
import com.wugui.datatx.core.util.JobRemotingUtil;

import java.util.List;

/**
 * admin api test
 *
 * @author xuxueli 2017-07-28 22:14:52
 */
public class AdminBizClient implements AdminBiz {

  private String addressUrl;
  private String accessToken;

  public AdminBizClient() {}

  public AdminBizClient(String addressUrl, String accessToken) {
    this.addressUrl = addressUrl;
    this.accessToken = accessToken;

    // valid
    if (!this.addressUrl.endsWith("/")) {
      this.addressUrl = this.addressUrl + "/";
    }
  }

  @Override
  public ReturnT<String> callback(List<HandleCallbackParam> callbackParamList) {
    return JobRemotingUtil.postBody(addressUrl + "api/callback", accessToken, callbackParamList, 3);
  }

  @Override
  public ReturnT<String> processCallback(List<HandleProcessCallbackParam> callbackParamList) {
    return JobRemotingUtil.postBody(
        addressUrl + "api/processCallback", accessToken, callbackParamList, 3);
  }

  @Override
  public ReturnT<String> registry(RegistryParam registryParam) {
    return JobRemotingUtil.postBody(addressUrl + "api/registry", accessToken, registryParam, 3);
  }

  @Override
  public ReturnT<String> registryRemove(RegistryParam registryParam) {
    return JobRemotingUtil.postBody(
        addressUrl + "api/registryRemove", accessToken, registryParam, 3);
  }
}
